package com.qishenyuan.competition.controller;


import com.qishenyuan.competition.annotation.TokenParam;
import com.qishenyuan.competition.common.Response;
import com.qishenyuan.competition.dto.UserCheckTokenReq;
import com.qishenyuan.competition.dto.UserLoginReq;
import com.qishenyuan.competition.dto.UserUpdateInfo;
import com.qishenyuan.competition.service.UserService;
import com.qishenyuan.competition.vo.UserInfoResp;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author qishenyuan
 * @since 2025-03-05
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    @RequestMapping("/login")
    public Response<UserInfoResp> login(@RequestBody @Valid UserLoginReq req) {
        UserInfoResp userInfoResp = userService.login(req);
        return Response.ok(userInfoResp);
    }

    @RequestMapping("/checkToken")
    public Response<UserInfoResp> checkLogin(@TokenParam String token,  @RequestBody UserCheckTokenReq req) {
        return Response.ok(userService.checkToken(token, req.getUid()));
    }

    @RequestMapping("/updateUserInfo")
    public Response<?> updateUserInfo(@RequestBody @Valid UserUpdateInfo req) {
        userService.updateUserInfo(req);
        return Response.ok();
    }
}

